<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="/bootstrap-3.3.7-dist\css\bootstrap.css">
    <script>
        function calculateJieCheng() {

            // var num = parseInt(document.getElementById("jiecheng"));
            // var sum = 1;
            // for (var i = num; i > 0; i--) {
            //     sum *= i
            // }
            // alert(num + "的阶乘是" + sum);
            var num1 = document.getElementById("jiecheng").value;
            var num = parseInt(num1);
            var result = factorial(num);
            // alert(num + "的阶乘是：" + result);
            var temp = document.getElementById("resultNum");
            temp.innerText = num + '的阶乘是：' + result;

        }
        // 阶乘函数定义
        function factorial(num) {
            if (num === 1) {
                return 1;
            } else {
                return num * factorial(num - 1)
            }
        }

    </script>
</head>

<body>
    <input type="text" id="jiecheng">
    <button class="btn btn-info" onclick="calculateJieCheng()">计算阶乘</button>
    <span id="resultNum"></span>
    <script>
        // 1、字面量方式创建对象
        var obj = {};
        console.log(obj);


        var student = {
            name: 'zhangsan',
            age: 23,
            study: function () {
                console.log(this.name + '在学习');
            }
        }
        // 给对象添加其他成员
        student.gender = '男';
        student.show = function () {
            console.log(this.name + ': show');
        }
        student.show();
        console.log(student);

        // 2、构造函数方式创建对象
        function Animal() {
            this.name = 'kitty';
            this.age = 23;
            this.run = function () {
                console.log(this.name + ' 正在跑步');
            }
        }
        var cat = new Animal();
        cat.run();

    </script>
</body>

</html>